#include "libOptimizer.h"

void removeNOP(vector<list<Opcode>> *irOut);

void Optimizer::optimize(vector<list<Opcode>> *irOut) {
	removeNOP(irOut);
}

//Removes all redundant NOP instructions
void removeNOP(vector<list<Opcode>> *irOut) {
	for (int i = 1; i < irOut->size(); ++i) {
		list<Opcode>::iterator nIt = (*irOut)[i].begin();
		++nIt;
		for (list<Opcode>::iterator it = (*irOut)[i].begin(); nIt != (*irOut)[i].end(); ++it, ++nIt) {
			if (it->ir == NOP && nIt->label == 0) {
				nIt->label = it->label;
				it = (*irOut)[i].erase(it);
				++nIt;
			}
		}
	}
}